home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 3
/
Info_Mac_1994-01.iso
/
User Interface
/
General
/
Extensions Manager Icon
/
DumbIcon.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-11
|
7KB
|
219 lines
/* DumbIcon.c */
#include <Quickdraw.h>
#include <Types.h>
#include <OSUtils.h>
#include <Resources.h>
#include <Memory.h>
#include <LoMem.h>
#include <SetUpA4.h>
/* Instructions for use: Include a bunch of ICN# icon resources in the */
/* file and they will get displayed. If you want color, make a */
/* 'cicn' color version of an already existing ICN# resource and give it */
/* the same ID. */
void Draw_Init_Icon (short icon_id);
void main(void)
{
short ResourceIndex;
Handle Resource;
Ptr MyInitPtr;
unsigned long RanSeed;
asm
{
move.l A0,MyInitPtr
}
RememberA0();
SetUpA4();
ResourceIndex = 1;
GetDateTime(&RanSeed);
LoopPoint:
Resource = Get1IndResource('ICN#',ResourceIndex);
if (Resource != (void*)0L)
{
Str255 Name;
short ID;
OSType Type;
long Stupid;
GetResInfo(Resource,&ID,&Type,Name);
Draw_Init_Icon(ID);
ResourceIndex += 1;
RanSeed = (RanSeed * 1103515245) + 12345;
Delay((RanSeed & 127) + 30,&Stupid);
goto LoopPoint;
}
RestoreA4();
}
/******************************************************************************
Draw_Init_Icon.c 1992 -- Chris Larson (cklarson@relleno.engr.ucdavis.edu)
This function will draw an Init's icon on the screen during startup.
Include the line,
extern void Draw_Init_Icon (short icon_id);
in your INIT source with your function prototypes and pass in the
resource ID of the icon you wish to be drawn. If color QD exists, the
function will attempt to draw a 'cicn' resource. If there is no color QD,
it will draw an 'icn#'. If an error occurs, SysBeep is called and nothing
is drawn.
Based upon the method of Paul Mercer, Darin Adler, and Paul Snively from an
idea by Steve Capps.
Code for compatablilty with IconWrap 1.2 based on similar code by Patrick
C. Beard, as modified by James W. Walker.
******************************************************************************/
#define DI_INITIAL_OFFSET 8
#define DI_BOTTOM_OFFSET 8
#define DI_ICON_HEIGHT 32
#define DI_ICON_WIDTH 32
#define DI_ICON_OFFSET 8
#define DI_NO_COLOR_QD 0x4000
#define DI_BEEP_LENGTH 30
#define DI_ICNPOUND_ROWBYTES 4
#define DI_INCPOUND_MASK_OFFSET 128
#define DI_CHECKSUM_CONSTANT 0x1021
#define DI_PVT_GBL_SIZE 76
#define LEFT_OFFSET_POINTER ((short *)0x092C) // Last 4 bytes of CurApName
#define CHECKSUM_POINTER ((short *)0x092E) // hold draw position and
// checksum.
typedef struct
{
Byte QD_Private_Global_Space[DI_PVT_GBL_SIZE];
long randseed;
BitMap screenBits;
Cursor arrow;
Pattern dkGray;
Pattern ltGray;
Pattern gray;
Pattern black;
Pattern white;
GrafPtr thePort;
} QD_Variables;
void Draw_Init_Icon (short icon_id)
{
CIconHandle icon_handle = NULL;
short usable_screen_width;
Rect destination_rect;
Rect source_rect;
BitMap icon_bitmap;
BitMap mask_bitmap;
GrafPort local_port;
QD_Variables my_vars;
long our_a5;
long old_a5;
long old_CurrentA5;
/* Prepare A5 for InitGraf call */
asm 68000
{
move.l CurrentA5,old_CurrentA5
move.l a5,old_a5
lea our_a5,a5
move.l a5,CurrentA5
}
/* InitGraf and open our GrafPort */
InitGraf (&(my_vars.thePort));
OpenPort (&local_port);
// Determine if position is valid. If not, set to initial value. If so, do
// nothing.
if ((((*LEFT_OFFSET_POINTER)<<1)^DI_CHECKSUM_CONSTANT) != (*CHECKSUM_POINTER))
*LEFT_OFFSET_POINTER = DI_INITIAL_OFFSET;
/* Compute destination Rect. */
usable_screen_width = local_port.portRect.right - local_port.portRect.left;
usable_screen_width -= usable_screen_width % (DI_ICON_WIDTH + DI_ICON_OFFSET);
if (((local_port.portRect.left + *LEFT_OFFSET_POINTER)/usable_screen_width) !=
((local_port.portRect.left + DI_ICON_WIDTH + *LEFT_OFFSET_POINTER)/usable_screen_width))
*LEFT_OFFSET_POINTER += DI_ICON_OFFSET + usable_screen_width -
((local_port.portRect.left + *LEFT_OFFSET_POINTER)%usable_screen_width);
destination_rect.left = ((local_port.portRect.left + (*LEFT_OFFSET_POINTER)) % usable_screen_width);
destination_rect.top = local_port.portRect.bottom - ((DI_ICON_HEIGHT+DI_BOTTOM_OFFSET) * (1+(*LEFT_OFFSET_POINTER)/usable_screen_width));
destination_rect.bottom = destination_rect.top + DI_ICON_HEIGHT;
destination_rect.right = destination_rect.left + DI_ICON_WIDTH;
/* If in color, use 'cicn'. If not, use 'ICN#'. SysBeep and return if resource unavailable. */
if (!(ROM85&DI_NO_COLOR_QD))
{
icon_handle = GetCIcon (icon_id);
if (!icon_handle)
{
goto UseBWIcon; /* hack by Thomas R. Lawrence */
SysBeep (DI_BEEP_LENGTH);
return;
}
PlotCIcon (&destination_rect,icon_handle);
DisposCIcon (icon_handle);
}
else
{
UseBWIcon:
icon_handle = (CIconHandle)GetResource ('ICN#',icon_id);
if (!icon_handle)
{
SysBeep(DI_BEEP_LENGTH);
return;
}
HLock ((Handle)icon_handle);
/* Set source Rect and intialize source BitMaps. */
SetRect (&source_rect,0,0,DI_ICON_HEIGHT,DI_ICON_WIDTH);
icon_bitmap.bounds = mask_bitmap.bounds = source_rect;
icon_bitmap.rowBytes = mask_bitmap.rowBytes = DI_ICNPOUND_ROWBYTES;
icon_bitmap.baseAddr = (Ptr)(*icon_handle);
mask_bitmap.baseAddr = (Ptr)(((Byte *)(*icon_handle))+DI_INCPOUND_MASK_OFFSET);
/* Draw the 'ICN#' using its mask. */
CopyMask (&icon_bitmap,&mask_bitmap,&(local_port.portBits),&source_rect,&source_rect,&destination_rect);
HUnlock ((Handle)icon_handle);
ReleaseResource ((Handle)icon_handle);
}
ClosePort (&local_port);
/* Update drawing position and checksum. */
*LEFT_OFFSET_POINTER += DI_ICON_WIDTH+DI_ICON_OFFSET;
*CHECKSUM_POINTER = ((*LEFT_OFFSET_POINTER)<<1)^DI_CHECKSUM_CONSTANT;
/* Reset A5 and CurrentA5 */
asm 68000
{
movea.l old_a5,a5
move.l old_CurrentA5,CurrentA5
}
}